package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.constant.MessageConstant;
import com.itheima.dao.SportDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Sprots;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import javax.management.RuntimeErrorException;
import javax.ws.rs.DELETE;

@Service(interfaceClass = SportService.class)
@Transactional
public class SportServiceImpl implements SportService {


    @Autowired
    private SportDao sportDao;
    /**
     * 添加运动库
     */
    public void addSport(Sprots sport) {
        System.out.println(sport);
        sportDao.addSport(sport);
    }

    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer pageSize = queryPageBean.getPageSize();
        Integer currentPage = queryPageBean.getCurrentPage();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage,pageSize);
        Page<Sprots> page = sportDao.findByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 根据id删除检查项
     * @param id
     */
    public void deleteById(Integer id) {
            sportDao.deleteById(id);
        }

    //编辑
    public void edit(Sprots sport) {
        sportDao.edit(sport);
    }

    //按照id查询
    public Sprots findSportById(Integer id) {
        return sportDao.findSportById(id);
    }
}
